package 剑指offer_leetcode;

/**
 * JZ21调整数组顺序使奇数位于偶数前面1
 */
public class 剑指Offer21_调整数组顺序使奇数位于偶数前面 {
    public int[] exchange(int[] nums) {
        int i =0 , j = nums.length-1;
        while(i<=j){
            if(nums[i]%2==1 && nums[j]%2==1){
                i++;
            }else if(nums[i]%2==1 && nums[j]%2==0){
                i++;
                j--;
            }else if(nums[i]%2==0 && nums[j]%2==1){
                int tmp = nums[j];
                nums[j--] = nums[i];
                nums[i++] = tmp;
            }else{
                j--;
            }
        }
        return nums;
    }
}
